import axios from 'axios';
import formatChannel from '../utils/formatChannel';
// 获取通道列表
export const getSubjectChannels = (pid) =>
  new Promise((resolve) => {
    axios({
      method: 'get',
      url: '/api/cityeyes/vfp/openapi/channel/v1/subject-channels',
      params: { pid },
    })
      .then((response) => {
        const { data } = response;
        if (data.code === 200 && data.data.channelList) {
          resolve(data.data.channelList);
        } else {
          resolve([]);
        }
      })
      .catch(() => {
        resolve([]);
      });
  });

// 获取通道列表
export const getPlayingDetails = (channelIds) =>
  new Promise((resolve) => {
    axios({
      method: 'get',
      url: '/api/cityeyes/vfp/openapi/video/v1/playing-details',
      params: { channelIds },
    })
      .then((response) => {
        const { data } = response;
        if (data.code === 200 && data.data) {
          const reuslt = {};
          data.data.forEach((f) => {
            reuslt[f.channelId] = formatChannel(f);
          });
          resolve(reuslt);
        } else {
          resolve(null);
        }
      })
      .catch(() => {
        resolve(null);
      });
  });
